home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / tcsh / dist / sh.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-21  |  25.3 KB  |  895 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.01/RCS/sh.h,v 3.26 1991/12/19 22:34:14 christos Exp $ */
  2. /*
  3.  * sh.h: Catch it all globals and includes file!
  4.  */
  5. /*-
  6.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Berkeley and its contributors.
  21.  * 4. Neither the name of the University nor the names of its contributors
  22.  *    may be used to endorse or promote products derived from this software
  23.  *    without specific prior written permission.
  24.  *
  25.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35.  * SUCH DAMAGE.
  36.  */
  37. #ifndef _h_sh
  38. #define _h_sh
  39.  
  40. /* This is separated instead of a #else of above because makedepend is
  41. easily confused. */
  42.  
  43. #ifndef CONFIGH
  44. # define CONFIGH "config.h"
  45. #endif
  46.  
  47. /*
  48.  * Avoid cpp bugs (CONFIGH is always defined at this point)
  49.  */
  50. #ifdef CONFIGH
  51. # include CONFIGH
  52. #endif
  53.  
  54. #ifndef EXTERN
  55. # define EXTERN extern
  56. #endif /* EXTERN */
  57. /*
  58.  * Sanity
  59.  */
  60. #if defined(_POSIX_SOURCE) && !defined(POSIX)
  61. # define POSIX
  62. #endif 
  63.  
  64. #if defined(POSIXJOBS) && !defined(BSDJOBS)
  65. # define BSDJOBS
  66. #endif 
  67.  
  68. #ifdef SHORT_STRINGS
  69. typedef short Char;
  70. # define SAVE(a) (Strsave(str2short(a)))
  71. #else
  72. typedef char Char;
  73. # define SAVE(a) (strsave(a))
  74. #endif 
  75.  
  76. /*
  77.  * If your compiler complains, then you can either
  78.  * throw it away and get gcc or, use the following define
  79.  * and get rid of the typedef.
  80.  * [The 4.2/3BSD vax compiler does not like that]
  81.  */
  82. #ifdef SIGVOID
  83. # if (defined(vax) || defined(uts)) && !defined(__GNUC__)
  84. #  define sigret_t void
  85. # else
  86. typedef void sigret_t;
  87. # endif 
  88. #else
  89. typedef int sigret_t;
  90. #endif /* SIGVOID */
  91.  
  92.  
  93. /*
  94.  * Fundamental definitions which may vary from system to system.
  95.  *
  96.  *    BUFSIZE        The i/o buffering size; also limits word size
  97.  *    MAILINTVL    How often to mailcheck; more often is more expensive
  98.  */
  99. #ifndef BUFSIZE
  100. #define    BUFSIZE    1024        /* default buffer size */
  101. #endif /* BUFSIZE */
  102.  
  103. #define FORKSLEEP    10    /* delay loop on non-interactive fork failure */
  104. #define    MAILINTVL    600    /* 10 minutes */
  105.  
  106. #ifndef INBUFSIZE
  107. # define INBUFSIZE    1024    /* Num input characters on the command line */
  108. #endif /* INBUFSIZE */
  109. /*
  110.  * The shell moves std in/out/diag and the old std input away from units
  111.  * 0, 1, and 2 so that it is easy to set up these standards for invoked
  112.  * commands.
  113.  */
  114. #define    FSHTTY    15        /* /dev/tty when manip pgrps */
  115. #define    FSHIN    16        /* Preferred desc for shell input */
  116. #define    FSHOUT    17        /* ... shell output */
  117. #define    FSHDIAG    18        /* ... shell diagnostics */
  118. #define    FOLDSTD    19        /* ... old std input */
  119.  
  120. #ifdef PROF
  121. #define    xexit(n)    done(n)
  122. #endif 
  123.  
  124. #ifdef cray
  125. # define word word_t           /* sys/types.h defines word.. bad move! */
  126. #endif
  127.  
  128. #include <sys/types.h>
  129.  
  130. #ifdef cray
  131. # undef word
  132. #endif 
  133.  
  134. /*
  135.  * This macro compares the st_dev field of struct stat. On aix on ibmESA
  136.  * st_dev is a structure, so comparison does not work. 
  137.  */
  138. #ifndef DEV_DEV_COMPARE
  139. # define DEV_DEV_COMPARE(x,y)   ((x) == (y))
  140. #endif /* DEV_DEV_COMPARE */
  141.  
  142. #ifdef _SEQUENT_
  143. # include <sys/procstats.h>
  144. #endif /* _SEQUENT_ */
  145. #if defined(POSIX) || SVID > 0
  146. # include <sys/times.h>
  147. #endif /* POSIX || SVID > 0 */
  148.  
  149. #ifdef NLS
  150. # include <locale.h>
  151. #endif 
  152.  
  153. #include <sys/param.h>
  154. #include <sys/stat.h>
  155.  
  156. #ifdef BSDTIMES
  157. # include <sys/time.h>
  158. # if SVID>3
  159. #  include "/usr/ucbinclude/sys/resource.h"
  160. # else
  161. #  include <sys/resource.h>
  162. # endif /* SVID>3 */
  163. #endif /* BSDTIMES */
  164.  
  165. #ifndef POSIX
  166. # ifdef TERMIO
  167. #  include <termio.h>
  168. # else /* SGTTY */
  169. #  include <sgtty.h>
  170. # endif /* TERMIO */
  171. #else /* POSIX */
  172. # include <termios.h>
  173. # if SVID > 3
  174. #  undef TIOCGLTC    /* we don't need those, since POSIX has them */
  175. #  undef TIOCSLTC
  176. #  undef CSWTCH
  177. #  define CSWTCH _POSIX_VDISABLE    /* So job control works */
  178. # endif /* SVID > 3 */
  179. #endif /* POSIX */
  180.  
  181. #ifdef POSIX
  182. /*
  183.  * We should be using setpgid and setpgid
  184.  * by now, but in some systems we use the
  185.  * old routines...
  186.  */
  187. # define getpgrp __getpgrp
  188. # define setpgrp __setpgrp
  189. # include <unistd.h>
  190. # undef getpgrp
  191. # undef setpgrp
  192. extern int getpgrp();
  193. extern int setpgrp();
  194.  
  195. /*
  196.  * the gcc+protoize version of <stdlib.h>
  197.  * redefines malloc(), so we define the following
  198.  * to avoid it.
  199.  */
  200. # define _GNU_STDLIB_H
  201. # define malloc __malloc
  202. # define free __free
  203. # define calloc __calloc
  204. # define realloc __realloc
  205. # include <stdlib.h>
  206. # undef malloc
  207. # undef free
  208. # undef calloc
  209. # undef realloc
  210. # include <limits.h>
  211. #endif /* POSIX */
  212.  
  213. #if SVID > 0 || defined(_IBMR2) || defined(_MINIX)
  214. # if !defined(pyr) && !defined(aiws) && !defined(stellar)
  215. #  include <time.h>
  216. # endif /* !aiws && !pyr && !stellar */
  217. #endif /* SVID > 0 ||  _IBMR2 */
  218.  
  219. #if !((defined(sun) || defined(_MINIX)) && defined(TERMIO))
  220. # include <sys/ioctl.h>
  221. #endif 
  222.  
  223. #if !defined(FIOCLEX) && defined(sun)
  224. # include <sys/filio.h>
  225. #endif /* !FIOCLEX && sun */
  226.  
  227.  
  228. #include <sys/file.h>
  229.  
  230. #if !defined(O_RDONLY) || !defined(O_NDELAY)
  231. # include <fcntl.h>
  232. #endif 
  233.  
  234. #include <errno.h>
  235.  
  236. #include <setjmp.h>
  237.  
  238. #if __STDC__
  239. # include <stdarg.h>
  240. #else
  241. # include <varargs.h>
  242. #endif 
  243.  
  244. #ifdef DIRENT
  245. # include <dirent.h>
  246. #else
  247. # ifdef hp9000s500
  248. #  include <ndir.h>
  249. # else
  250. #  include <sys/dir.h>
  251. # endif
  252. # define dirent direct
  253. #endif /* DIRENT */
  254. #if defined(hpux) || defined(sgi)
  255. # include <stdio.h>    /* So the fgetpwent() prototypes work */
  256. #endif 
  257. #include <pwd.h>
  258. #ifdef PW_SHADOW
  259. # include <shadow.h>
  260. #endif /* PW_SHADOW */
  261. #ifdef BSD
  262. # include <strings.h>
  263. # define strchr(a, b) index(a, b)
  264. # define strrchr(a, b) rindex(a, b)
  265. #else
  266. # include <string.h>
  267. #endif /* BSD */
  268.  
  269.  
  270. /*
  271.  * ANSIisms... These must be *after* the system include and 
  272.  * *before* our includes, so that BSDreno has time to define __P
  273.  */
  274. #ifndef __P
  275. # if __STDC__
  276. #  define __P(a) a
  277. # else
  278. #  define __P(a) ()
  279. #  define const
  280. #  ifndef apollo
  281. #   define volatile    /* Apollo 'c' extensions need this */
  282. #  endif /* apollo */
  283. # endif 
  284. #endif 
  285.  
  286.  
  287. typedef int bool;
  288.  
  289. #include "sh.types.h"
  290.  
  291. #ifndef lint
  292. typedef ptr_t memalign_t;
  293. #else
  294. typedef union {
  295.     char    am_char, *am_char_p;
  296.     short   am_short, *am_short_p;
  297.     int     am_int, *am_int_p;
  298.     long    am_long, *am_long_p;
  299.     float   am_float, *am_float_p;
  300.     double  am_double, *am_double_p;
  301. }      *memalign_t;
  302.  
  303. # define malloc        lint_malloc
  304. # define free        lint_free
  305. # define realloc    lint_realloc
  306. # define calloc        lint_calloc
  307. #endif 
  308.  
  309. #ifdef MDEBUG
  310. extern memalign_t    DebugMalloc    __P((unsigned, char *, int));
  311. extern memalign_t    DebugRealloc    __P((ptr_t, unsigned, char *, int));
  312. extern memalign_t    DebugCalloc    __P((unsigned, unsigned, char *, int));
  313. extern void        DebugFree    __P((ptr_t, char *, int));
  314. # define xmalloc(i)      DebugMalloc(i, __FILE__, __LINE__)
  315. # define xrealloc(p, i)((p) ? DebugRealloc(p, i, __FILE__, __LINE__) : \
  316.                   DebugMalloc(i, __FILE__, __LINE__))
  317. # define xcalloc(n, s)    DebugCalloc(n, s, __FILE__, __LINE__)
  318. # define xfree(p)        if (p) DebugFree(p, __FILE__, __LINE__); else
  319. #else
  320. # ifdef SYSMALLOC
  321. #  define xmalloc(i)      Malloc(i)
  322. #  define xrealloc(p, i)Realloc(p, i)
  323. #  define xcalloc(n, s)    Calloc(n, s)
  324. #  define xfree(p)        Free(p)
  325. # else
  326. # define xmalloc(i)      malloc(i)
  327. # define xrealloc(p, i)    realloc(p, i)
  328. # define xcalloc(n, s)    calloc(n, s)
  329. # define xfree(p)        free(p)
  330. # endif /* SYSMALLOC */
  331. #endif /* MDEBUG */
  332. #include "sh.char.h"
  333. #include "sh.err.h"
  334. #include "sh.dir.h"
  335. #include "sh.proc.h"
  336.  
  337. #include "pathnames.h"
  338.  
  339.  
  340. /*
  341.  * C shell
  342.  *
  343.  * Bill Joy, UC Berkeley
  344.  * October, 1978; May 1980
  345.  *
  346.  * Jim Kulp, IIASA, Laxenburg Austria
  347.  * April, 1980
  348.  */
  349.  
  350. #define SIGN_EXTEND_CHAR(a) \
  351.     ((int) ((a) & 0x80 ? ((int) (a)) | 0xffffff00 : ((int) a) & 0x000000ff))
  352.  
  353.  
  354.  
  355. #if !defined(MAXNAMLEN) && defined(_D_NAME_MAX)
  356. # define MAXNAMLEN _D_NAME_MAX
  357. #endif /* MAXNAMLEN */
  358.  
  359. #ifndef MAXHOSTNAMELEN
  360. # define MAXHOSTNAMELEN    255
  361. #endif /* MAXHOSTNAMELEN */
  362.  
  363.  
  364.  
  365. #define    eq(a, b)    (Strcmp(a, b) == 0)
  366.  
  367. /* globone() flags */
  368. #define G_ERROR        0    /* default action: error if multiple words */
  369. #define G_IGNORE    1    /* ignore the rest of the words           */
  370. #define G_APPEND    2    /* make a sentence by cat'ing the words    */
  371.  
  372. /*
  373.  * Global flags
  374.  */
  375. EXTERN bool    chkstop;        /* Warned of stopped jobs... allow exit */
  376.  
  377. #ifndef FIOCLEX
  378. EXTERN bool    didcch;        /* Have closed unused fd's for child */
  379. #endif 
  380.  
  381. EXTERN bool    didfds;        /* Have setup i/o fd's for child */
  382. EXTERN bool    doneinp;        /* EOF indicator after reset from readc */
  383. EXTERN bool    exiterr;        /* Exit if error or non-zero exit status */
  384. EXTERN bool    child;        /* Child shell ... errors cause exit */
  385. EXTERN bool    haderr;        /* Reset was because of an error */
  386. EXTERN bool    intty;        /* Input is a tty */
  387. EXTERN bool    intact;        /* We are interactive... therefore prompt */
  388. EXTERN bool    justpr;        /* Just print because of :p hist mod */
  389. EXTERN bool    loginsh;        /* We are a loginsh -> .login/.logout */
  390. EXTERN bool    neednote;    /* Need to pnotify() */
  391. EXTERN bool    noexec;        /* Don't execute, just syntax check */
  392. EXTERN bool    pjobs;        /* want to print jobs if interrupted */
  393. EXTERN bool    setintr;        /* Set interrupts on/off -> Wait intr... */
  394. EXTERN bool    timflg;        /* Time the next waited for command */
  395. EXTERN bool    havhash;        /* path hashing is available */
  396. EXTERN bool    editing;        /* doing filename expansion and line editing */
  397. EXTERN bool    bslash_quote;    /* PWP: tcsh-style quoting?  (in sh.c) */
  398. EXTERN bool    isoutatty;    /* is SHOUT a tty */
  399. EXTERN bool    isdiagatty;    /* is SHDIAG a tty */
  400. EXTERN bool    is1atty;        /* is file descriptor 1 a tty (didfds mode) */
  401. EXTERN bool    is2atty;        /* is file descriptor 2 a tty (didfds mode) */
  402.  
  403. /*
  404.  * Global i/o info
  405.  */
  406. EXTERN Char   *arginp;        /* Argument input for sh -c and internal `xx` */
  407. EXTERN int     onelflg;        /* 2 -> need line for -t, 1 -> exit on read */
  408. EXTERN Char   *ffile;        /* Name of shell file for $0 */
  409.  
  410. extern char *seterr;        /* Error message from scanner/parser */
  411. extern int errno;        /* Error from C library routines */
  412. EXTERN Char   *shtemp;        /* Temp name for << shell files in /tmp */
  413.  
  414. #ifdef BSDTIMES
  415. EXTERN struct timeval time0;    /* Time at which the shell started */
  416. EXTERN struct rusage ru0;
  417. #else
  418. # ifdef _SEQUENT_
  419. EXTERN timeval_t time0;        /* Time at which the shell started */
  420. EXTERN struct process_stats ru0;
  421. # else /* _SEQUENT_ */
  422. #  ifndef POSIX
  423. EXTERN time_t  time0;        /* time at which shell started */
  424. #  else    /* POSIX */
  425. EXTERN clock_t time0;        /* time at which shell started */
  426. #  endif /* POSIX */
  427. EXTERN struct tms shtimes;    /* shell and child times for process timing */
  428. # endif /* _SEQUENT_ */
  429. #endif /* BSDTIMES */
  430.  
  431. /*
  432.  * Miscellany
  433.  */
  434. EXTERN Char   *doldol;        /* Character pid for $$ */
  435. EXTERN int     backpid;        /* pid of the last background job */
  436. EXTERN time_t  chktim;        /* Time mail last checked */
  437.  
  438. /*
  439.  * Ideally these should be uid_t, gid_t, pid_t. I cannot do that right now
  440.  * cause pid's could be unsigned and that would break our -1 flag, and 
  441.  * uid_t and gid_t are not defined in all the systems so I would have to
  442.  * make special cases for them. In the future...
  443.  */
  444. EXTERN int     uid;        /* Invokers uid */
  445. EXTERN int     gid;        /* Invokers gid */
  446. EXTERN int     opgrp,        /* Initial pgrp and tty pgrp */
  447.                shpgrp,        /* Pgrp of shell */
  448.                tpgrp;        /* Terminal process group */
  449.                 /* If tpgrp is -1, leave tty alone! */
  450.  
  451. EXTERN Char    PromptBuf[INBUFSIZE*2]; /* buffer for the actual printed prompt.
  452.                        * this must be large enough to contain
  453.                        * the input line and the prompt, in
  454.                        * case a correction occured...
  455.                        */
  456.  
  457. /*
  458.  * To be able to redirect i/o for builtins easily, the shell moves the i/o
  459.  * descriptors it uses away from 0,1,2.
  460.  * Ideally these should be in units which are closed across exec's
  461.  * (this saves work) but for version 6, this is not usually possible.
  462.  * The desired initial values for these descriptors are defined in
  463.  * sh.local.h.
  464.  */
  465. EXTERN int   SHIN;        /* Current shell input (script) */
  466. EXTERN int   SHOUT;        /* Shell output */
  467. EXTERN int   SHDIAG;        /* Diagnostic output... shell errs go here */
  468. EXTERN int   OLDSTD;        /* Old standard input (def for cmds) */
  469.  
  470. /*
  471.  * Error control
  472.  *
  473.  * Errors in scanning and parsing set up an error message to be printed
  474.  * at the end and complete.  Other errors always cause a reset.
  475.  * Because of source commands and .cshrc we need nested error catches.
  476.  */
  477.  
  478. extern jmp_buf reslab;
  479.  
  480. /* bugfix by Jak Kirman @ Brown U.: remove the (void) cast here, see sh.c */
  481. #define    setexit()    (setjmp(reslab))
  482. #define    reset()        longjmp(reslab, 1)
  483.  /* Should use structure assignment here */
  484. #define    getexit(a)    copy((char *)(a), (char *)reslab, sizeof reslab)
  485. #define    resexit(a)    copy((char *)reslab, ((char *)(a)), sizeof reslab)
  486.  
  487. EXTERN Char   *gointr;        /* Label for an onintr transfer */
  488.  
  489. EXTERN sigret_t (*parintr) ();    /* Parents interrupt catch */
  490. EXTERN sigret_t (*parterm) ();    /* Parents terminate catch */
  491.  
  492. /*
  493.  * Lexical definitions.
  494.  *
  495.  * All lexical space is allocated dynamically.
  496.  * The eighth/sixteenth bit of characters is used to prevent recognition,
  497.  * and eventually stripped.
  498.  */
  499. #define        META        0200
  500. #define        ASCII        0177
  501. #ifdef SHORT_STRINGS
  502. # define    QUOTE     ((Char)    0100000)/* 16nth char bit used for 'ing */
  503. # define    TRIM        0077777    /* Mask to strip quote bit */
  504. # define    UNDER        0040000    /* Underline flag */
  505. # define    BOLD        0020000    /* Bold flag */
  506. # define    STANDOUT    0010000    /* Standout flag */
  507. # define    LITERAL        0004000    /* Literal character flag */
  508. # define    ATTRIBUTES    0074000    /* The bits used for attributes */
  509. # define    CHAR        0000377    /* Mask to mask out the character */
  510. #else
  511. # define    QUOTE     ((Char)    0200)    /* Eighth char bit used for 'ing */
  512. # define    TRIM        0177    /* Mask to strip quote bit */
  513. # define    UNDER        0000000    /* No extra bits to do both */
  514. # define    BOLD        0000000    /* Bold flag */
  515. # define    STANDOUT    META    /* Standout flag */
  516. # define    LITERAL        0000000    /* Literal character flag */
  517. # define    ATTRIBUTES    0200    /* The bits used for attributes */
  518. # define    CHAR        0000177    /* Mask to mask out the character */
  519. #endif 
  520.  
  521. EXTERN int     AsciiOnly;    /* If set only 7 bits expected in characters */
  522.  
  523. /*
  524.  * Each level of input has a buffered input structure.
  525.  * There are one or more blocks of buffered input for each level,
  526.  * exactly one if the input is seekable and tell is available.
  527.  * In other cases, the shell buffers enough blocks to keep all loops
  528.  * in the buffer.
  529.  */
  530. EXTERN struct Bin {
  531.     off_t   Bfseekp;        /* Seek pointer */
  532.     off_t   Bfbobp;        /* Seekp of beginning of buffers */
  533.     off_t   Bfeobp;        /* Seekp of end of buffers */
  534.     int     Bfblocks;        /* Number of buffer blocks */
  535.     Char  **Bfbuf;        /* The array of buffer blocks */
  536. }       B;
  537.  
  538. /*
  539.  * This structure allows us to seek inside aliases
  540.  */
  541. struct Ain {
  542.     int type;
  543. #define I_SEEK -1        /* Invalid seek */
  544. #define A_SEEK    0        /* Alias seek */
  545. #define F_SEEK    1        /* File seek */
  546. #define E_SEEK    2        /* Eval seek */
  547.     off_t f_seek;
  548.     Char **a_seek;
  549. } ;
  550.  
  551. extern int aret;        /* Type of last char returned */
  552. #define SEEKEQ(a, b) ((a)->type == (b)->type && \
  553.               (a)->f_seek == (b)->f_seek && \
  554.               (a)->a_seek == (b)->a_seek)
  555.  
  556. #define    fseekp    B.Bfseekp
  557. #define    fbobp    B.Bfbobp
  558. #define    feobp    B.Bfeobp
  559. #define    fblocks    B.Bfblocks
  560. #define    fbuf    B.Bfbuf
  561.  
  562. /*
  563.  * The shell finds commands in loops by reseeking the input
  564.  * For whiles, in particular, it reseeks to the beginning of the
  565.  * line the while was on; hence the while placement restrictions.
  566.  */
  567. EXTERN struct Ain lineloc;
  568.  
  569. EXTERN bool    cantell;        /* Is current source tellable ? */
  570.  
  571. /*
  572.  * Input lines are parsed into doubly linked circular
  573.  * lists of words of the following form.
  574.  */
  575. struct wordent {
  576.     Char   *word;
  577.     struct wordent *prev;
  578.     struct wordent *next;
  579. };
  580.  
  581. /*
  582.  * During word building, both in the initial lexical phase and
  583.  * when expanding $ variable substitutions, expansion by `!' and `$'
  584.  * must be inhibited when reading ahead in routines which are themselves
  585.  * processing `!' and `$' expansion or after characters such as `\' or in
  586.  * quotations.  The following flags are passed to the getC routines
  587.  * telling them which of these substitutions are appropriate for the
  588.  * next character to be returned.
  589.  */
  590. #define    DODOL    1
  591. #define    DOEXCL    2
  592. #define    DOALL    DODOL|DOEXCL
  593.  
  594. /*
  595.  * Labuf implements a general buffer for lookahead during lexical operations.
  596.  * Text which is to be placed in the input stream can be stuck here.
  597.  * We stick parsed ahead $ constructs during initial input,
  598.  * process id's from `$$', and modified variable values (from qualifiers
  599.  * during expansion in sh.dol.c) here.
  600.  */
  601. EXTERN Char   *lap;
  602.  
  603. /*
  604.  * Parser structure
  605.  *
  606.  * Each command is parsed to a tree of command structures and
  607.  * flags are set bottom up during this process, to be propagated down
  608.  * as needed during the semantics/exeuction pass (sh.sem.c).
  609.  */
  610. struct command {
  611.     short   t_dtyp;        /* Type of node          */
  612. #define    NODE_COMMAND    1    /* t_dcom <t_dlef >t_drit     */
  613. #define    NODE_PAREN    2    /* ( t_dspr ) <t_dlef >t_drit     */
  614. #define    NODE_PIPE    3    /* t_dlef | t_drit         */
  615. #define    NODE_LIST    4    /* t_dlef ; t_drit         */
  616. #define    NODE_OR        5    /* t_dlef || t_drit         */
  617. #define    NODE_AND    6    /* t_dlef && t_drit         */
  618.     short   t_dflg;        /* Flags, e.g. F_AMPERSAND|...      */
  619. /* save these when re-doing      */
  620. #ifndef apollo
  621. #define    F_SAVE    (F_NICE|F_TIME|F_NOHUP)    
  622. #else
  623. #define    F_SAVE    (F_NICE|F_TIME|F_NOHUP|F_VER)
  624. #endif 
  625. #define    F_AMPERSAND    (1<<0)    /* executes in background     */
  626. #define    F_APPEND    (1<<1)    /* output is redirected >>     */
  627. #define    F_PIPEIN    (1<<2)    /* input is a pipe         */
  628. #define    F_PIPEOUT    (1<<3)    /* output is a pipe         */
  629. #define    F_NOFORK    (1<<4)    /* don't fork, last ()ized cmd     */
  630. #define    F_NOINTERRUPT    (1<<5)    /* should be immune from intr's */
  631. /* spare */
  632. #define    F_STDERR    (1<<7)    /* redirect unit 2 with unit 1     */
  633. #define    F_OVERWRITE    (1<<8)    /* output was !             */
  634. #define    F_READ        (1<<9)    /* input redirection is <<     */
  635. #define    F_REPEAT    (1<<10)    /* reexec aft if, repeat,...     */
  636. #define    F_NICE        (1<<11)    /* t_nice is meaningful      */
  637. #define    F_NOHUP        (1<<12)    /* nohup this command          */
  638. #define    F_TIME        (1<<13)    /* time this command          */
  639. #ifdef apollo
  640. #define F_VER        (1<<14)    /* execute command under SYSTYPE */
  641. #endif 
  642.     union {
  643.     Char   *T_dlef;        /* Input redirect word          */
  644.     struct command *T_dcar;    /* Left part of list/pipe      */
  645.     }       L;
  646.     union {
  647.     Char   *T_drit;        /* Output redirect word      */
  648.     struct command *T_dcdr;    /* Right part of list/pipe      */
  649.     }       R;
  650. #define    t_dlef    L.T_dlef
  651. #define    t_dcar    L.T_dcar
  652. #define    t_drit    R.T_drit
  653. #define    t_dcdr    R.T_dcdr
  654.     Char  **t_dcom;        /* Command/argument vector      */
  655.     struct command *t_dspr;    /* Pointer to ()'d subtree      */
  656.     short   t_nice;
  657. #ifdef F_VER
  658.     short   t_systype;
  659. #endif 
  660. };
  661.  
  662.  
  663. /*
  664.  * The keywords for the parser
  665.  */
  666. #define    T_BREAK        0
  667. #define    T_BRKSW        1
  668. #define    T_CASE        2
  669. #define    T_DEFAULT     3
  670. #define    T_ELSE        4
  671. #define    T_END        5
  672. #define    T_ENDIF        6
  673. #define    T_ENDSW        7
  674. #define    T_EXIT        8
  675. #define    T_FOREACH    9
  676. #define    T_GOTO        10
  677. #define    T_IF        11
  678. #define    T_LABEL        12
  679. #define    T_LET        13
  680. #define    T_SET        14
  681. #define    T_SWITCH    15
  682. #define    T_TEST        16
  683. #define    T_THEN        17
  684. #define    T_WHILE        18
  685.  
  686. /*
  687.  * These are declared here because they want to be
  688.  * initialized in sh.init.c (to allow them to be made readonly)
  689.  */
  690.  
  691. extern struct biltins {
  692.     char   *bname;
  693. #if defined(hpux) && defined(__STDC__) && !defined(__GNUC__)
  694.     /* Avoid hpux ansi mode spurious warnings */
  695.     void    (*bfunct) ();
  696. #else
  697.     void    (*bfunct) __P((Char **, struct command *));
  698. #endif /* hpux && __STDC__ && !__GNUC__ */
  699.     int     minargs, maxargs;
  700. }       bfunc[];
  701. extern int nbfunc;
  702.  
  703. extern struct srch {
  704.     char   *s_name;
  705.     int     s_value;
  706. }       srchn[];
  707. extern int nsrchn;
  708.  
  709. /*
  710.  * Structure defining the existing while/foreach loops at this
  711.  * source level.  Loops are implemented by seeking back in the
  712.  * input.  For foreach (fe), the word list is attached here.
  713.  */
  714. EXTERN struct whyle {
  715.     struct Ain   w_start;    /* Point to restart loop */
  716.     struct Ain   w_end;        /* End of loop (0 if unknown) */
  717.     Char  **w_fe, **w_fe0;    /* Current/initial wordlist for fe */
  718.     Char   *w_fename;        /* Name for fe */
  719.     struct whyle *w_next;    /* Next (more outer) loop */
  720. }      *whyles;
  721.  
  722. /*
  723.  * Variable structure
  724.  *
  725.  * Aliases and variables are stored in AVL balanced binary trees.
  726.  */
  727. EXTERN struct varent {
  728.     Char  **vec;        /* Array of words which is the value */
  729.     Char   *v_name;        /* Name of variable/alias */
  730.     struct varent *v_link[3];    /* The links, see below */
  731.     int     v_bal;        /* Balance factor */
  732. }       shvhed, aliases;
  733.  
  734. #define v_left        v_link[0]
  735. #define v_right        v_link[1]
  736. #define v_parent    v_link[2]
  737.  
  738. extern struct varent *adrof1();
  739.  
  740. #define adrof(v)    adrof1(v, &shvhed)
  741. #define value(v)    value1(v, &shvhed)
  742.  
  743. /*
  744.  * The following are for interfacing redo substitution in
  745.  * aliases to the lexical routines.
  746.  */
  747. EXTERN struct wordent *alhistp;    /* Argument list (first) */
  748. EXTERN struct wordent *alhistt;    /* Node after last in arg list */
  749. EXTERN Char  **alvec, *alvecp;    /* The (remnants of) alias vector */
  750.  
  751. /*
  752.  * Filename/command name expansion variables
  753.  */
  754. EXTERN int   gflag;        /* After tglob -> is globbing needed? */
  755.  
  756. #define MAXVARLEN 30        /* Maximum number of char in a variable name */
  757.  
  758. #ifndef MAXPATHLEN
  759. # define MAXPATHLEN 2048
  760. #endif /* MAXPATHLEN */
  761.  
  762. #ifndef MAXNAMLEN
  763. # define MAXNAMLEN 512
  764. #endif /* MAXNAMLEN */
  765.  
  766. /*
  767.  * Variables for filename expansion
  768.  */
  769. extern Char **gargv;        /* Pointer to the (stack) arglist */
  770. extern long gargc;        /* Number args in gargv */
  771.  
  772. /*
  773.  * Variables for command expansion.
  774.  */
  775. extern Char **pargv;        /* Pointer to the argv list space */
  776. extern long pargc;        /* Count of arguments in pargv */
  777. EXTERN Char   *pargs;        /* Pointer to start current word */
  778. EXTERN long    pnleft;        /* Number of chars left in pargs */
  779. EXTERN Char   *pargcp;        /* Current index into pargs */
  780.  
  781. /*
  782.  * History list
  783.  *
  784.  * Each history list entry contains an embedded wordlist
  785.  * from the scanner, a number for the event, and a reference count
  786.  * to aid in discarding old entries.
  787.  *
  788.  * Essentially "invisible" entries are put on the history list
  789.  * when history substitution includes modifiers, and thrown away
  790.  * at the next discarding since their event numbers are very negative.
  791.  */
  792. EXTERN struct Hist {
  793.     struct wordent Hlex;
  794.     int     Hnum;
  795.     int     Href;
  796.     time_t  Htime;
  797.     Char   *histline;
  798.     struct Hist *Hnext;
  799. }       Histlist;
  800.  
  801. EXTERN struct wordent paraml;    /* Current lexical word list */
  802. EXTERN int     eventno;        /* Next events number */
  803. EXTERN int     lastev;        /* Last event reference (default) */
  804.  
  805. EXTERN Char    HIST;        /* history invocation character */
  806. EXTERN Char    HISTSUB;        /* auto-substitute character */
  807.  
  808. /*
  809.  * To print system call errors...
  810.  */
  811. extern char *sys_errlist[];
  812. extern int errno, sys_nerr;
  813.  
  814. /*
  815.  * strings.h:
  816.  */
  817. #ifndef SHORT_STRINGS
  818. #define Strchr(a, b)          strchr(a, b)
  819. #define Strrchr(a, b)      strrchr(a, b)
  820. #define Strcat(a, b)          strcat(a, b)
  821. #define Strncat(a, b, c)     strncat(a, b, c)
  822. #define Strcpy(a, b)          strcpy(a, b)
  823. #define Strncpy(a, b, c)     strncpy(a, b, c)
  824. #define Strlen(a)        strlen(a)
  825. #define Strcmp(a, b)        strcmp(a, b)
  826. #define Strncmp(a, b, c)    strncmp(a, b, c)
  827.  
  828. #define Strspl(a, b)        strspl(a, b)
  829. #define Strsave(a)        strsave(a)
  830. #define Strend(a)        strend(a)
  831. #define Strstr(a, b)        strstr(a, b)
  832.  
  833. #define str2short(a)         (a)
  834. #define blk2short(a)         saveblk(a)
  835. #define short2blk(a)         saveblk(a)
  836. #define short2str(a)         strip(a)
  837. #else
  838. #define Strchr(a, b)       s_strchr(a, b)
  839. #define Strrchr(a, b)         s_strrchr(a, b)
  840. #define Strcat(a, b)          s_strcat(a, b)
  841. #define Strncat(a, b, c)     s_strncat(a, b, c)
  842. #define Strcpy(a, b)          s_strcpy(a, b)
  843. #define Strncpy(a, b, c)    s_strncpy(a, b, c)
  844. #define Strlen(a)        s_strlen(a)
  845. #define Strcmp(a, b)        s_strcmp(a, b)
  846. #define Strncmp(a, b, c)    s_strncmp(a, b, c)
  847.  
  848. #define Strspl(a, b)        s_strspl(a, b)
  849. #define Strsave(a)        s_strsave(a)
  850. #define Strend(a)        s_strend(a)
  851. #define Strstr(a, b)        s_strstr(a, b)
  852. #endif 
  853.  
  854. /*
  855.  * setname is a macro to save space (see sh.err.c)
  856.  */
  857. EXTERN char   *bname;
  858.  
  859. #define    setname(a)    (bname = (a))
  860.  
  861. #ifdef VFORK
  862. EXTERN Char   *Vsav;
  863. EXTERN Char   *Vdp;
  864. EXTERN Char   *Vexpath;
  865. EXTERN char  **Vt;
  866. #endif /* VFORK */
  867.  
  868. EXTERN Char  **evalvec;
  869. EXTERN Char   *evalp;
  870.  
  871. extern struct mesg {
  872.     char   *iname;        /* name from /usr/include */
  873.     char   *pname;        /* print name */
  874. }       mesg[];
  875.  
  876. /* word_chars is set by default to WORD_CHARS but can be overridden by
  877.    the worchars variable--if unset, reverts to WORD_CHARS */
  878.  
  879. EXTERN Char   *word_chars;
  880.  
  881. #define WORD_CHARS "*?_-.[]~="    /* default chars besides alnums in words */
  882.  
  883. EXTERN Char   *STR_SHELLPATH;
  884.  
  885. #ifdef _PATH_BSHELL
  886. EXTERN Char   *STR_BSHELL;
  887. #endif 
  888. EXTERN Char   *STR_WORD_CHARS;
  889. EXTERN Char  **STR_environ;
  890.  
  891. #include "tc.h"
  892. #include "sh.decls.h"
  893.  
  894. #endif /* _h_sh */
  895.